/**
* 作者 ：sunmeng
*
* 日期 ：2017/11/21
*
* 描述 ：目录审核
*/
<template>
  <el-container class="is-vertical">
    <HeaderBar :menuState="menuState"></HeaderBar>
    <BreadCrumb :options="breadOptions" class="breadcreamb"></BreadCrumb>
    <el-main>
      <ModuleBar :title="moduleBarTitle"></ModuleBar>
      <MTable :options="tableOptions" ref="myTable" class="tablebar"></MTable>
    </el-main>
      <Dialog :options="dialogOptions">
	      <AdoptForm slot="dialogContent" :options="dialogOptions" ref="adoptForm" v-if="dialogOptions.visible"></AdoptForm>
	    </Dialog>
  </el-container>
</template>
<script>
	import axios from '../../plugins/axios'
  import checkDirAPIs from '../../api/checkDirAPIs'
  import HeaderBar from '../../components/header/Header.vue'
  import BreadCrumb from '../../components/breadcrumb/BreadCrumb.vue'
  import ModuleBar from '../../components/modulebar/ModuleBar.vue'
  import MTable from '../../components/table/Table.vue'
  import Dialog from '../../components/dialog/Dialog.vue'
  import AdoptForm from './components/adoptForm/AdoptForm.vue'

  export default {
    name: 'catalogAuditing',
    components: {
      HeaderBar,
      BreadCrumb,
      ModuleBar,
      MTable,
      Dialog,
      AdoptForm
    },
    data () {
    	let vm = this;
      return {
        menuState: "/catalogAuditing/main",
        moduleBarTitle:"审核列表",
        breadOptions:{
        	bread:[
            {
              label:"政务数据资源管理系统",
              path:"/"
            },{
              label:"目录审核",
              path:"/catalogAuditing/main"
            }
        	]
        },
        tableOptions: {
	        handleSelectionChange (rows) {
	        }
        },
        dialogOptions: {
	        visible: false,
	        title: "提示",
	        label:"通过意见 :"
	      },
	      selectRows:[]

      }
    },
    mounted () {
      let vm = this,
        pageNo = 1,
        pageSize = 20;
      	vm.cataForm(pageNo, pageSize)
    },
    methods: {
    	cataForm (pageNo, pageSize) {
        let vm = this
        checkDirAPIs.list({
          pageNum: pageNo,
          pageSize: pageSize,
          token: localStorage.token,
        }).then(({ data }) => {
          if(data.code == 10000) {
          	console.log(data);
            vm.initTable(data.data, pageNo, pageSize, data.total)
          }
        })
      },
      cataExamine (keyValue,checkOption){
      	let vm = this,
      	pageNo = vm.tableOptions.pageInfo.currentPage,
        pageSize = vm.tableOptions.pageInfo.pageSize;
      	checkDirAPIs.adopt({
					token:localStorage.token,
					key:keyValue,
					checkOpinion:checkOption
				}).then(({ data }) => {
					console.log(data);
					if(data.code = 10000){
	          vm.cataForm(pageNo, pageSize)
						vm.dialogOptions.visible = false
					}
				});
      },
      cataOverrule (keyValue,checkOption){
      	let vm = this,
      	pageNo = vm.tableOptions.pageInfo.currentPage,
        pageSize = vm.tableOptions.pageInfo.pageSize;
      	checkDirAPIs.reject({
					token:localStorage.token,
					key:keyValue,
					checkOpinion:checkOption
				}).then(({ data }) => {
					console.log(data);
					if(data.code = 10000){
	          vm.cataForm(pageNo, pageSize)
						vm.dialogOptions.visible = false
					}
				});
      },
      initTable (dataList, pageNo, pageSize, total) {
        let vm = this
        vm.tableOptions = {
          thead: [{
            prop: "infoResourceCode", // 数据的key值
            label: "信息资源代码"
          },{
            prop: "infoResourceName", // 数据的key值
            label: "信息资源名称"
          },{
            prop: "departmentName", // 数据的key值
            label: "提供方"
          },{
            prop: "abstracts", // 数据的key值
            label: "信息资源摘要"
          },{
            prop: "status", // 数据的key值
            label: "资源状态",
            formatter (row, column, cellValue) {
              switch (cellValue) {
                case 1 :
                  return "新增未提交"
                  break
                case 2 :
                  return "已提交待审核"
                  break
                case 3 :
                  return "审核未通过"
                  break
                case 4 :
                  return "审核通过已发布"
                  break
              }
            }
          },{
            prop: "createTime", // 数据的key值
            label: "注册时间"
          }],
        operation:{
        	items: [{
            xtype: "link",
            buttonType: "danger", // 按钮样式
            buttonText: "查看",
            onClick (i, row) {
              vm.$router.push({path: '/catalogAuditing/cataDetails', query:{id:row.infoResourceId}});
            }
          },{
            xtype: "link",
            buttonType: "danger", // 按钮样式
            buttonText: "通过",
            onClick (i, row) {
              vm.dialogOptions.visible = true;
              vm.dialogOptions.label = "通过意见";
              vm.dialogOptions.infoResourceId = row.infoResourceId;
              vm.dialogOptions.submit=function(){
								vm.cataExamine(vm.$refs.adoptForm.$refs.infoId.value,vm.$refs.adoptForm.getRefs("refName").$refs.textarea.value)
              };
              vm.dialogOptions.cancel=function(){
        				vm.dialogOptions.visible = false
        				vm.$refs.adoptForm.getRefs("refName").$refs.textarea.value =""
              };
            }
          },{
            xtype: "link",
            buttonType: "danger", // 按钮样式
            buttonText: "驳回",
            onClick (i, row) {
              vm.dialogOptions.visible = true;
              vm.dialogOptions.label = "驳回意见";
              vm.dialogOptions.infoResourceId = row.infoResourceId;
            	vm.dialogOptions.submit=function(){
              	vm.cataOverrule(vm.$refs.adoptForm.$refs.infoId.value,vm.$refs.adoptForm.getRefs("refName").$refs.textarea.value);
              };
              vm.dialogOptions.cancel=function(){
        				vm.dialogOptions.visible = false
        				vm.$refs.adoptForm.getRefs("refName").$refs.textarea.value =""
              };
            }
          }]
        },
        data: dataList,
        pageInfo: {
            currentPage: pageNo,
            pageSizes: [20, 40, 60, 80],
            pageSize: pageSize,
            layout: "prev, pager, next, total, sizes, jumper",
            total: total,
            handleSizeChange (val) {
              vm.tableOptions.pageInfo.pageSize = val;
							vm.cataForm(vm.tableOptions.pageInfo.currentPage, vm.tableOptions.pageInfo.pageSize)
            },
            handleCurrentChange (val) {
              vm.tableOptions.pageInfo.pageSize = val;
							vm.cataForm(vm.tableOptions.pageInfo.currentPage, vm.tableOptions.pageInfo.pageSize)
            }
        },
        handleSelectionChange (rows) {
          console.log(rows)
          vm.selectRows = rows
        },
        selection: {
            width: 55,
        },
        toolbar: [{
        		xtype: "toolbarRow",
        		items:[{
	            xtype: "button",
	            buttonType: "primary", // 按钮样式
	            buttonText: "批量审核",
	            style:"background:#076dc1;margin:20px 20px 0 0",
	            onClick () {
	              let codeAll = "";
	              if(vm.selectRows.length == 0){
	              	vm.$message({
				            type: 'warning',
				            message: '您还没有选择数据!'
				          });
	              }else{
		              for(let i=0;i<vm.selectRows.length;i++){
		              //	console.log(vm.selectRows[i].infoResourceId)
		              	codeAll += vm.selectRows[i].infoResourceId +","
		              };
									vm.cataExamine(codeAll,"");
	              }
	            }
	          },{
	            xtype: "button",
	            buttonType: "primary", // 按钮样式
	            buttonText: "批量驳回",
	            style:"background:#076dc1;margin:20px 20px 0 0",
	            onClick () {
	              let codeAll = "";
	              if(vm.selectRows.length == 0){
	              	vm.$message({
				            type: 'warning',
				            message: '您还没有选择数据!'
				          });
	              }else{
		              for(let i=0;i<vm.selectRows.length;i++){
		              	codeAll += vm.selectRows[i].infoResourceId +","
		              };
		              vm.cataOverrule(codeAll,"");
	              }
	            }
        		}]
          }]
        }
      }
    }
  }
</script>
<style>
	.tablebar{
		width: 94%;
		margin: 0 auto;
	}
	.tableContainer table td button:last-child span{
		color: #e15959;
	}
</style>
